<template>
  <div class="WorkingSchedule" v-loading="loading">
    <div class="myechart" v-if="echartsData && echartsData.date.length">
      <div id="postponenum" class="echartsStyle"></div>
    </div>
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="仓检姓名" class="myform-item">
          <el-input
            v-model="form.qc_user"
            placeholder="请输入仓检姓名"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="仓检日期">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="form.qc_time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button @click="onSearch" type="primary">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="仓检姓名" align="center" prop="qc_user">
      </el-table-column>
      <!-- <el-table-column
        label="仓检日期"
        align="center"
        prop="qc_date"
      >
      </el-table-column> -->
      <el-table-column label="合格数" align="center" prop="pass">
      </el-table-column>
      <el-table-column label="不合格数" align="center" prop="nopass">
      </el-table-column>
      <el-table-column label="总数" align="center" prop="passtotal">
      </el-table-column>
      <el-table-column label="合格率" align="center" prop="passrate">
        <template slot-scope="{ row }"
          >{{ (row.passrate * 100).toFixed(2) }}%</template
        >
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postApiCodeGetQtuserrate"
    />
  </div>
</template>

<script>
import * as echarts from "echarts";
import { postApiCodeGetQtuserrate } from "@/api";
import { getSevenMonth, getCurrentTime } from "@/utils/time.js";
import pagination from "@/components/pagination.vue";
import { postponenumcang } from "./postponenum.js";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      echartsData: "",
      form: {
        qc_user: "",
        qc_time: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  async activated() {
    this.dateSeven();
    let form = this.form;
    await this.postApiCodeGetQtuserrate(form);
    await this.postponenum(postponenumcang(this.echartsData));
  },
  methods: {
    dateSeven() {
      let seven = getSevenMonth();
      let time = getCurrentTime();
      this.form.qc_time = [seven, time];
    },
    async postponenum(data) {
      let myChart = echarts.init(document.getElementById("postponenum"));
      // 绘制图表
      myChart.setOption(data);
    },
    // 运营列表
    async postApiCodeGetQtuserrate(data) {
      this.loading = true;
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.qc_time) {
        form.qc_time = `${form.qc_time[0]}/${form.qc_time[1]}`;
      }
      postApiCodeGetQtuserrate(form)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data.list;
          this.tableData = res.data.list;
          this.total = Number(res.total);
          this.echartsData = res.data;
          if (res.data.date.length) {
            console.log("Res.data------>", res);
            this.$nextTick(() => {
              this.postponenum(postponenumcang(res.data));
            });
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postApiCodeGetQtuserrate(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.echartsStyle {
  width: calc(100% - 40px);
  height: 400px;
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
